<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>发射站所属组配置管理</title>
    <meta name="decorator" content="nblank"/>
</head>
<body>
<div class="content container">
    <h2 class="page-title">发射站所属组配置管理
        <small> &nbsp;发射站所属组配置${not empty param.id?'修改':'添加'}</small>
    </h2>
    <section class="widget widget-tabs widget-table-overflow ">
        <header>
            <ul class="nav nav-tabs">
                <li><a href="${ctx}/biz/sgroup">组列表&nbsp;</a></li>
                <li><a href="${ctx}/biz/sgcfg?sgroupId=${cfg2.sgroup.id}&itemId=${cfg2.gitem.id}&groupId=${cfg2.group.id}&stationId=${cfg2.station.id}">组配置列表&nbsp;(${station.name})</a></li>
                <li class="active"><a href="javascript:void(0)">组配置${not empty param.id?'修改':'添加'}&nbsp;(${station.name})</a>
                </li>
            </ul>
        </header>
        <div class="body tab-content">
            <form:form id="inputForm" modelAttribute="cfg2" action="${ctx}/biz/sgcfg/save" method="post" class="form-horizontal">
                <form:hidden path="sgcfg.id"/>
                <form:hidden path="gitem.id"/>
                <form:hidden path="gitem.name"/>
                <form:hidden path="sgroup.id"/>
                <form:hidden path="sgroup.name"/>
                <form:hidden path="sgcfg.sgroup.id"/>
                <form:hidden path="sgcfg.gitem.id"/>
                <form:hidden path="station.id"/>
                <form:hidden path="station.name"/>
                <form:hidden path="group.id"/>
                <form:hidden path="group.name"/>
                <form:hidden path="sgroupTypeName"/>
                <form:hidden path="modelName"/>


                <div class="form-group">
                    <label id="gitemName" class="control-label col-sm-4"><span class="help-inline">设备名:</label>
                    <div class="col-sm-4" style="margin-top: 6px;">
                        ${cfg2.gitem.name}
                    </div>
                </div>

                <div class="form-group">
                    <label for="sgcfg.modelId" class="control-label col-sm-4"><span class="help-inline"><font
                            color="red">*</font> </span> 设备型号:</label>
                    <div class="col-sm-8">
                        <form:select name="modelName" path="sgcfg.modelId" class="selectpicker"  data-style="btn-primary">
                            <form:option value="" label="请择选"/>
                            <form:options items="${fns:getDictList('biz_equip_model')}"
                                          itemValue="value" itemLabel="label" htmlEscape="false"/>
                        </form:select>
                        <p id="modelTip" style="display: none">请选择设备型号</p>
                    </div>
                </div>
                <div class="form-group">
                    <label for="sgcfg.ipPort" class="control-label col-sm-4"><span class="help-inline"><font
                            color="red">*</font> </span>
                        IP和端口:</label>
                    <div class="col-sm-4">
                        <form:input name="ipPort" path="sgcfg.ipPort" htmlEscape="false" maxlength="50"
                                    class="form-control input-transparent"/>
                        <p id="ipPortTip" style="display: none">请填写有效的ip和端口</p>
                    </div>
                </div>
                <div class="form-group">
                    <label for="other1" class="control-label col-sm-4">
                        备用参数1:</label>
                    <div class="col-sm-4">
                        <form:input id="other1" path="sgcfg.other1" htmlEscape="false" maxlength="50"
                                    class="form-control input-transparent"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="other2" class="control-label col-sm-4">
                        备用参数1:</label>
                    <div class="col-sm-4">
                        <form:input id="other2" path="sgcfg.other2" htmlEscape="false" maxlength="50"
                                    class="form-control input-transparent"/>
                    </div>
                </div>

                <div class="form-actions">
                    <div class="text-align-center">
                        <input id="btnCancel" class="btn btn-default" type="button"
                               style="margin-left: -50px;min-width:100px;" value="返 回" onclick="history.go(-1)"/>
                        <input id="btnSubmit" class="btn btn-primary" style="margin-left:50px;min-width:100px;"
                               type="submit" value="保 存"/>&nbsp;
                    </div>
                </div>
            </form:form>
        </div>
    </section>
</div>
<script type="text/javascript">
    //ip:port 格式验证
    var test=/^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]):\d{2,5}$/;
    jQuery.validator.addMethod("regex",function(value, element, params){  //扩展方法示例:　　
        var exp = new RegExp(test); //params rules的value传入的正则表达式
        return exp.test(value);       //value  被验证的input传入的值
    },"输入格式有误");

    $(function () {
//    $("#sgcfg\\.ipPort").blur(function(){
//        //ip格式验证
//        if($("#sgcfg\\.ipPort").val()!=""){
//            console.info("1111");
//            if(!test.test($("#sgcfg\\.ipPort").val())){
//                $("#ipPortTip").css("display","block");
//            }else{
//                console.info("22222");
//                $("#ipPortTip").css("display","none");
//            }
//        }else{
//            $("#ipPortTip").css("display","none");
//        }
//    });


    $('.selectpicker').on('changed.bs.select', function (e) {
        if($('.selectpicker').val()==""){
            $("#modelTip").css("display","block");
        }else {
            $("#modelTip").css("display", "none");
        }
    });
    $("#inputForm").validate({
        rules: {
            "sgcfg.ipPort": {
                "required":true,
                "regex":true
            }
        },
            messages:{
            "sgcfg.ipPort": {
                required:"必填部分",
                regex:"请填写正确的格式，例如192.168.1.1:2333"
            }
        },
        invalidHandler: function (event, validator) {
            $("#btnSubmit").attr("disabled", false);
        },
        submitHandler: function (form) {
            if($('.selectpicker').val()==""){
                $("#modelTip").css("display","block");
            }else{
                $(form).find(":submit").attr("disabled", true).attr("value", "提交中...");
                $(form).ajaxSubmit({
                    success: function (result) {
                        Messenger().post("操作成功!");
                        pxTrigDlg("${ctx}/biz/sgcfg?sgroupId=${cfg2.sgroup.id}&itemId=${cfg2.gitem.id}&groupId=${cfg2.group.id}&stationId=${cfg2.station.id}");
                    }
                })
            }
        }
    })

});
</script>

</body>
</html>